package leetcodecompetition.D344;

import java.util.HashSet;
import java.util.Set;

public class T6416 {
    public int[] distinctDifferenceArray(int[] nums) {
        Set<Integer> set = new HashSet<>();
        int n = nums.length;
        int[] diff = new int[n];
        for (int i = 0; i < n; i++) {
            set.add(nums[i]);
            diff[i] = set.size();
        }
        set.clear();
        for (int i = n - 1; i >= 0; i--) {
            diff[i]=diff[i]-set.size();
            set.add(nums[i]);
        }
        return diff;
    }
}
